import { _decorator, AudioClip, AudioSource, Component, Label, Node, Slider } from "cc";
import { back } from "./back";
const { ccclass, property } = _decorator;

@ccclass("j16")
export class j16 extends back {
  @property(AudioSource) audioSource1: AudioSource;
  @property(AudioSource) audioSource2: AudioSource;
  // mp3 资源 第一个是 bgm 第二个是 click 音效
  @property([AudioClip]) audioClips: AudioClip[] = [];
  // 显示音乐音量
  @property(Label) label: Label;
  volume = 1;
  start() {
    this.label.string = `当前音量: ${this.volume}`;
  }
  onClickMusicEffect() {
    this.audioSource1.playOneShot(this.audioClips[0], this.volume);
  }

  onClickMusicBgm() {
    if (this.audioSource2.playing) {
      this.audioSource2.stop();
    } else {
      this.audioSource2.clip = this.audioClips[1];
      this.audioSource2.volume = this.volume;
      this.audioSource2.loop = true;
      this.audioSource2.play();
    }
  }

  onSlider(slider: Slider) {
    this.volume = slider.progress;
    this.label.string = `当前音量: ${this.volume}`;
    this.audioSource2.volume = this.volume;
  }
  update(deltaTime: number) {}
}
